// packageI/anytime_service/order/order_detail/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language:{},
    urlStr:"",
    evaluation_show: false,
    timeList: [{
      id: 1,
      name: '接单时间',
      time:""
    },{
      id: 2,
      name: '完成时间',
      time:""
    }],
    type: "individual",//area-区域代管理、skill-技能师傅管理
    order_id:"",
    point:{},
    info:{},
    order_type:"",
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    let language = wx.getStorageSync("langIndex");
    this.setData({
      language: language.en,
      type:options.name,
      order_id:options.order_id,
      order_type:options.order_type
    })
    let address_point = wx.getStorageSync('address-point') || wx.getStorageSync('applyaddresspoint');
    if(address_point){
      this.setData({
        point:address_point.point
      })
    }
    this.getData();
  },

  commentEvent(){
    this.getData();
    this.setData({
      order_type:"5"
    })
  },
  goToAdress(){
    //打开地图
    // let point = app.BMapTransqqMap(parseFloat(this.data.info.longitude),parseFloat(this.data.info.latitude));
    let point = {
      lat: parseFloat(this.data.info.latitude),
      lng: parseFloat(this.data.info.longitude)
    };
    wx.openLocation({
      latitude: point.lat,
      longitude:  point.lng,
      scale: 18,
      name: this.data.info.full_address
    });
  },
  order_receiving(){
    app._postNetWork({
      url:app.getNetAddresss('plugin.be-within-call.frontend.need-order-operate.receive'),
      data:{
        oid:this.data.order_id
      },
      success:resdata=>{
        let {result,msg} = resdata.data;
        app.tips(msg);
        if(result){
          this.setData({order_type:"2"})
          this.getData();
        }
      }
    })
  },
  getData(){
    let urlStr = "plugin.be-within-call.frontend.area-manage.order-detail";
    if(this.data.type == 'individual'){
      urlStr ='plugin.be-within-call.frontend.order.shi-fu.detail';
    }
    app._getNetWork({
      url:app.getNetAddresss(urlStr),
      data:{
        oid:this.data.order_id,lng:this.data.point.lng,lat:this.data.point.lat
      },
      success:resdata=>{
        let {result,msg,data} = resdata.data;
        if(result){
          this.setData({
            info:data,
          })
          console.log(this.data.order_type);
          if(this.data.order_type==1|| this.data.order_type==5){
            console.log(data.accept_time,"accept_time");
            console.log(data.complete_time,"complete_time");
            let  timeList= [{
              id: 1,
              name: '接单时间',
              time:data.accept_time
            },{
              id: 2,
              name: '完成时间',
              time:data.complete_time
            }];
            this.setData({
              timeList
            })
          }
        }else{
          app.tips(msg);
        }
      }
    })
  },
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  // 我要评价
  btnEvaluation() {
    // let url = "";
    // if(this.data.info.need_type == 1){
    //   url= 'plugin.be-within-call.frontend.need-order-operate.shi-fu-remark'
    // }else{
    //   url = 'plugin.be-within-call.frontend.need-order-operate.push-remark';
    // }
    this.setData({
      evaluation_show: true,
      urlStr:"plugin.be-within-call.frontend.need-order-operate.shi-fu-remark",
    })
  },
})